package com.heatingcharge.controller.base;


import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.ChargePriceDTO;
import com.heatingcharge.param.ChargePriceParam;
import com.heatingcharge.service.base.IChargePriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-10-15
 */
@RestController
@RequestMapping("/charge-price")
public class ChargePriceController {
    @Autowired
    IChargePriceService chargePriceService;

    @GetMapping
    public R getHeatPrice(ChargePriceDTO chargePriceDTO){
        List<ChargePriceDTO> chargePrice = chargePriceService.getChargePrice(chargePriceDTO);
        return R.ok(chargePrice);
    }

    @PostMapping
    public R save(@RequestBody ChargePriceParam chargePriceParam){
        if (chargePriceService.save(chargePriceParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @PutMapping
    public R update(@RequestBody ChargePriceParam chargePriceParam){
        if (chargePriceService.update(chargePriceParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id){
        if (chargePriceService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

